<template>
    <div ref="chart" style="width: 450px; height: 350px; background-color: white; margin-top: 30px;"></div>
</template>

<script setup>
import { onMounted, ref, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';

const chart = ref(null);

const initChart = () => {
    const myChart = echarts.init(chart.value);

    const option = {
        title: {
            text: '各类用餐支出比例',
            subtext: '2024年度数据',
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: '用餐类型',
                type: 'pie',
                radius: '50%',
                data: [
                    { value: 400, name: '快餐' },
                    { value: 200, name: '中餐' },
                    { value: 300, name: '西餐' },
                    { value: 150, name: '小吃' },
                    { value: 50, name: '饮料' }
                ],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ],
        color: ['#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF']
    };

    myChart.setOption(option);
};

onMounted(() => {
    initChart();
});

onBeforeUnmount(() => {
    echarts.dispose(chart.value);
});




</script>

<style scoped>
/* 可以添加样式来美化图表 */
</style>